package com.lcj.login;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

public class RenRen {
    /*以下是模拟登陆程序*/
    /*输入你的用户名及密码 ，这里输入*/
    private static String userName = "15874991816";
    private static String password = "cx821202";
    private static String redirectURL = "http://www.renren.com/465530468/profile?v=info_timeline";
    // Don't change the following URL
    private static String renRenLoginURL = "https://www.zptong.com/plus/ajax_user.php";
    // The HttpClient is used in one session
    private HttpResponse response;
    CloseableHttpClient httpClient = HttpClients.createDefault();
    /*输入抓包的参数，即传递的参数*/
    private boolean login() throws Exception {
        HttpPost httpost = new HttpPost(renRenLoginURL);
        // All the parameters post to the web site
        //建立一个NameValuePair数组，用于存储欲传送的参数，添加相关参数，见上图中的参数
        //"username": $("#username").val(),"password": $("#password").val(),"expire":expire,"url":window.location.href,"postcaptcha":$("#postcaptcha").val(),"time": new Date().getTime(),"act":"do_login"

        List<NameValuePair> nvps = new ArrayList<NameValuePair>();

        nvps.add(new BasicNameValuePair("username", userName));
        nvps.add(new BasicNameValuePair("password", password));
        nvps.add(new BasicNameValuePair("expire", "7"));

        nvps.add(new BasicNameValuePair("url", ""));

        nvps.add(new BasicNameValuePair("postcaptcha", ""));
        nvps.add(new BasicNameValuePair("time", String.valueOf(System.currentTimeMillis())));
        nvps.add(new BasicNameValuePair("act", "do_login"));



        /*登陆成功，获取返回的数据，即html文件*/
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        String ee = httpClient.execute(httpost,responseHandler);
        System.out.println("eeeeeeeeeeeeee=========="+ee);
       // httpost.abort();
      //  DefaultHttpClient httpclient2 = new DefaultHttpClient();
        HttpGet httpget = new HttpGet("https://www.zptong.com/plus/ajax_contact.php?id=98729&time="+System.currentTimeMillis()+"&act=jobs_contact");

       // HttpGet httpget = new HttpGet("https://www.zptong.com/jobs/jobs-show-98729-.htm");



        String responseBody = "";
        try {
             responseBody =  httpClient.execute(httpget,responseHandler);
        } catch (Exception e) {
            e.printStackTrace();
            responseBody = null;
        } finally {
            httpget.abort();
            httpClient.close();
        }
        System.out.println("ssssssssssssssss"+responseBody);
            return true;


    }

    /*main方法*/
    public static void main(String[] args) throws Exception {
        RenRen renRen = new RenRen();
        renRen.login();
    }
}
